//
//  LXBookingTimeView.m
//  lixing
//
//  Created by ypj on 2022/6/25.
//

#import "LXBookingTimeView.h"
#import "LXAppointmentModel.h"
@implementation LXBookingTimeView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = UIColor.whiteColor;
        [self addCorner:4];
        
        
        //预约
        UIImage *imge = [UIImage imageNamed:@"订单预约成功"];
        self.bookingImgV = [[UIImageView alloc] initWithFrame:CGRectMake(self.X_width - imge.size.width - 15, -3, imge.size.width, imge.size.height)];
        self.bookingImgV.image = imge;
        [self addSubview:self.bookingImgV];
        
        
        //时间lb
        self.bookingRightLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 3, imge.size.width, self.bookingImgV.height/2)];
        self.bookingRightLab.textAlignment = NSTextAlignmentCenter;
        self.bookingRightLab.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
        self.bookingRightLab.textColor = UIColor.whiteColor;
        [self.bookingImgV addSubview:self.bookingRightLab];
        
    
        //预约时间icon
        UIImageView *timeIcon = [[UIImageView alloc] initWithFrame:CGRectMake(15, 13, 12, 12)];
        timeIcon.image = [UIImage imageNamed:@"icon_预约时间"];
        [self addSubview:timeIcon];
        
        //时间lb
        UILabel *timeLB = [[UILabel alloc] initWithFrame:CGRectMake(timeIcon.X_width + 3, timeIcon.Y - 1, 100, 14)];
        timeLB.text = @"预约时间";
        timeLB.font = [UIFont systemFontOfSize:12];
        timeLB.textColor = ColorWithAAAAAA;
        [self addSubview:timeLB];
        
        self.bookingTimeLB = [[UILabel alloc] initWithFrame:CGRectMake(timeIcon.X, timeLB.Y_height + 4, 200, 16)];
        _bookingTimeLB.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
        _bookingTimeLB.textColor = ColorWith333333;
        [self addSubview:_bookingTimeLB];
        
        //地址icon
        UIImageView *addressIcon = [[UIImageView alloc] initWithFrame:CGRectMake(timeIcon.X, _bookingTimeLB.Y_height + 10, 11, 14)];
        addressIcon.image = [UIImage imageNamed:@"icon_看车地址"];
        [self addSubview:addressIcon];
        
        //地址label
        UILabel *addressLB = [[UILabel alloc] initWithFrame:CGRectMake(timeIcon.X_width + 1, addressIcon.Y - 1, 100, 14)];
        addressLB.text = @"看车地址";
        addressLB.font = [UIFont systemFontOfSize:12];
        addressLB.textColor = ColorWithAAAAAA;
        [self addSubview:addressLB];
        
        self.bookingAddressLB = [[UILabel alloc] initWithFrame:CGRectMake(timeIcon.X, addressLB.Y_height + 4, self.width - 30, 35)];
        _bookingAddressLB.numberOfLines = 2;
        _bookingAddressLB.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
        [self addSubview:_bookingAddressLB];
        
        self.cancelBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _cancelBtn.frame = CGRectMake(15, _bookingAddressLB.Y_height + 16, self.width / 2 - 4.5 - 15, 35);
        [_cancelBtn setTitle:@"取消预约" forState:(UIControlStateNormal)];
        [_cancelBtn setTitleColor:ColorWith333333 forState:(UIControlStateNormal)];
        _cancelBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [_cancelBtn addCorner:3 AndLine:[UIColor colorWithHexString:@"#F5F5F5"]];
        [self addSubview:_cancelBtn];
        
        self.submitBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _submitBtn.frame = CGRectMake(self.width / 2 + 4.5, _cancelBtn.Y, _cancelBtn.width, 35);
        [_submitBtn setTitle:@"确认预约" forState:(UIControlStateNormal)];
        _submitBtn.backgroundColor = ColorWith3C6CFC;
        [_submitBtn setTitleColor:UIColor.whiteColor forState:(UIControlStateNormal)];
        _submitBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [_submitBtn addCorner:3];
        [self addSubview:_submitBtn];
    }
    return self;
}

- (void)setModel:(LXAppointmentModel *)model {
    _model = model;
    
    self.bookingImgV.hidden = YES;
    // 预约成功的
    if ([model.status intValue]==1) {
        self.bookingImgV.hidden = NO;
        if ([[NSString getNowTimeTimestamp:@"yyyy-MM-dd HH:mm"] integerValue] > [NSString timeSwitchTimestamp:model.appointTime andFormatter:@"yyyy-MM-dd HH:mm"]) {
            self.bookingRightLab.textColor = ColorWithAAAAAA;
            self.bookingImgV.image = [UIImage imageNamed:@"订单已结束"];
            
        }
        else {
            self.bookingRightLab.textColor = UIColor.whiteColor;
            self.bookingImgV.image = [UIImage imageNamed:@"订单预约成功"];
        }
        
    }
    // 已取消
    else if([model.status intValue] == 3){
        [self.submitBtn setTitle:@"重新预约" forState:UIControlStateNormal];
        [self.cancelBtn setTitle:@"删除订单" forState:UIControlStateNormal];
        
    }
    self.bookingRightLab.text = [NSString timestampSwitchTime:[NSString timeSwitchTimestamp:model.appointTime andFormatter:@"yyyy-MM-dd HH:mm"] /1000 andFormatter:@"MM月dd"];

    
    self.bookingTimeLB.text = [NSString timestampSwitchTime:[NSString timeSwitchTimestamp:model.appointTime andFormatter:@"yyyy-MM-dd HH:mm"] /1000 andFormatter:@"yyyy年MM月dd日 HH:mm"];
    self.bookingAddressLB.text = model.companyAddr;
//        self.bookingAddressLB.text = @"上海市塑料袋积分两三点积分四点了附件塑料袋积分十来点杰弗里斯发塑料袋会计法";
}
@end
